import com.alibaba.fastjson2.JSON;
import com.ruoyi.system.commons.utils.Constants;
import com.ruoyi.system.domain.dto.ToolJsonDto;
import org.apache.commons.text.StringSubstitutor;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author QiuYuchun
 * Date: 2023/12/19
 * Time: 9:49
 */
public class HelloWorld {
    @Test
    public void main(String[] args) {
        String filePath = "C:/Users/QYC/Downloads/postMethod.json"; // 替换为你的文件绝对路径
        try {
            String content = new String(Files.readAllBytes(Paths.get(filePath)));
            System.out.println(content);
            ToolJsonDto tool = JSON.parseObject(content,ToolJsonDto.class);
            String promptTemplate = Constants.TOOL_PROMPT_TEMPLATE;
            Map valuesMap = new HashMap<>();
            valuesMap.put("toolSetRole",tool.getToolSetRole());
            valuesMap.put("toolName", tool.getToolName());
            List<ToolJsonDto.Body.Required> paramPairs = new ArrayList<>();
            paramPairs = tool.getBody().getRequired();
            String paramModel = Constants.PARAM_TEMPLATE;

            String paramModels = "";
            for(ToolJsonDto.Body.Required paramPair : paramPairs){
                String paramName = paramPair.getDescription();
                Map valuesMap2 = new HashMap<>();
                valuesMap2.put("paramName",paramName);
                StringSubstitutor sub2 = new StringSubstitutor(valuesMap2);
                paramModels += sub2.replace(paramModel);
            }
            valuesMap.put("paramModels", paramModels);
            StringSubstitutor sub = new StringSubstitutor(valuesMap);
            String resolvedString = sub.replace(promptTemplate);
            System.out.println(resolvedString);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
